package ms.core.gateway.response;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lombok.Data;
import ms.core.common.utils.UploadedFileUtils.FileDoc;
import ms.core.common.utils.UploadedFileUtils.UrlDoc;
import ms.core.gateway.bean.SysCorpBean;
import ms.core.gateway.response.DicConstVO.ConstItem;
import ms.core.gateway.system.Application;
import ms.core.gateway.utils.DicConstUtils;
import ms.core.tool.JsonTool;
import ms.core.tool.StrTool;

@Data
public class SysCorpVO extends SysCorpBean {
	/**
	 * 获取企业类型名
	 * 
	 * @return
	 */
	public String getCtypeName() {
		int ctype = getCtype();

		List<String> names = new ArrayList<>();
		List<ConstItem> list = DicConstUtils.getConst("SYS2", "ctype", true);
		for(ConstItem item: list) {
			int id = StrTool.strToInt(item.getId().toString(), 0);
			if ((id & ctype)>0) names.add(item.getValue());
		}
		return StrTool.strListToStr(names, ",");
	}

	/**
	 * 扩展信息转map对象
	 * 
	 * @return
	 */
	public Map<String, Object> getExtObj() {
		return StrTool.isBlank(getExt()) ? new HashMap<>() : JsonTool.objectToMap(getExt(), false);
	}
	
	/**
	 * 企业资料类别转对象
	 * 
	 * @return
	 */
	public List<String> getDocTypeList() {
		List<String> list = JsonTool.jsonToListBean(getDocType(), String.class);
		return list==null ? new ArrayList<>() : list;
	}
	
	/**
	 * 企业资料转对象
	 * 
	 * @return
	 */
	public List<UrlDoc> getDocList() {
		List<UrlDoc> files = new ArrayList<>();
		List<FileDoc> list = JsonTool.jsonToListBean(getDocs(), FileDoc.class);
		if (list==null)
			return files;
		
		for(FileDoc doc: list) {
			UrlDoc e = new UrlDoc();
			e.setCatalog(doc.getCatalog());
			e.setDesc(doc.getDesc());
			e.setName(doc.getName());
			String url = Application.DIR_CORP_DOC.getWeb()+"/"+doc.getFile();
			e.setUrl(url);
			
			files.add(e);
		}
		
		return files;
	}
	
	/**
	 * 获取状态名
	 * 
	 * @return
	 */
	public String getStateName() {
		return getState()==0 ? "正常" : "注销";
	}
}